package com.yuncheng.spcyApi.service.impl;

import cn.hutool.core.collection.CollectionUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.yuncheng.spcyApi.constant.other.YwlxmbConstant;
import com.yuncheng.spcyApi.entity.SpcySqsxYwlxmb;
import com.yuncheng.spcyApi.mapper.SpcySqsxYwlxmbMapper;
import com.yuncheng.spcyApi.service.ISpcySqsxYwlxmbService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

import com.yuncheng.common.base.service.impl.BaseServiceImpl;

import java.util.List;
import java.util.Optional;

/**
 * @Description: 审评查验-业务类型模板
 * @Author: yuncheng
 * @Date: 2023-10-31
 * @Version: V1.0
 */
@Service
public class SpcySqsxYwlxmbServiceImpl extends BaseServiceImpl<SpcySqsxYwlxmbMapper, SpcySqsxYwlxmb> implements ISpcySqsxYwlxmbService {

    @Override
    public String getJcyjBySqsxId(String fywflcode) {
        if (StringUtils.isBlank(fywflcode)){
            return "xxx";
        }

        List<SpcySqsxYwlxmb> list = list(new LambdaQueryWrapper<SpcySqsxYwlxmb>()
                .eq(SpcySqsxYwlxmb::getFmblx, YwlxmbConstant.MBLX_JCYJ)
                .eq(SpcySqsxYwlxmb::getFmbly, fywflcode));
        if (CollectionUtil.isEmpty(list)){
            return "xxx";
        }

        return Optional.ofNullable(list.get(0)).map(m->m.getFmbnr()).orElseGet(()->"xxx");
    }

    @Override
    public String getJcyjByJclxAndSqsxId(String fywflcode, String jclx) {
        if (StringUtils.isBlank(fywflcode)){
            return "xxx";
        }

        if (StringUtils.isNotBlank(jclx)) {
            List<SpcySqsxYwlxmb> list = list(new LambdaQueryWrapper<SpcySqsxYwlxmb>()
                    .eq(SpcySqsxYwlxmb::getFmblx, YwlxmbConstant.MBLX_JCYJ)
                    .eq(SpcySqsxYwlxmb::getFmbly, fywflcode)
                    .like(SpcySqsxYwlxmb::getFmbywlx, jclx));
            if (CollectionUtil.isEmpty(list)) {
                return getJcyjBySqsxId(fywflcode);
            }else {
                return Optional.ofNullable(list.get(0)).map(m->m.getFmbnr()).orElseGet(()->"xxx");
            }
        }

        return getJcyjBySqsxId(fywflcode);
    }
}
